// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: declaration of CXFormsElementUpload.
//   $Id$
#ifndef __UPLOADUI_H
#define __UPLOADUI_H 1

#pragma once

#include "FormControlInputUI.h"
#include "parse.h"
#include <base64.h>

class CXFormsElementUpload : public CXFormsElementFormControlInput
{
public:
	virtual HRESULT handleEvent(DISPID eventID, VARIANT *pvarResult,DISPPARAMS* pdispparams);
	virtual HRESULT attachEvents( IHTMLDocument3 * pDoc3 = 0);
	CXFormsElementUpload();
	virtual ~CXFormsElementUpload();

	virtual CImpl * CreateImpl();
	virtual CXFormsParse* CreateParse(CImpl* pImpl);
	virtual HRESULT get_value(BSTR* psValue);
	virtual HRESULT getSignificantDescendentNodes(IHTMLDocument3 * pDoc3);
	HRESULT get_filename(BSTR * psValue);
	HRESULT get_mimeType(BSTR * psValue);
	virtual HRESULT put_value(BSTR sValue);
	virtual HRESULT ElementReady(void);

private:
	
	//on initialise, the processor will look up potential file extensions
	//	for the given mimetype attribute. this variable stores that.
	CString m_sFileExtensionFilter;
	
	//These two contain the values for the appropriate child elements
	//	in order to monitor them for changes.
	CComBSTR m_sFilePath;
	CComBSTR m_sFileName;

	//when the selection changes, the user is asking the processor
	//	to open a stream for upload, either to an existing file, 
	//	or an input device.
	HRESULT getBinaryStream();

	//external tool for encoding binaries as base64.
	CComPtr<Icodec> m_pCodec;
//	BASE64Lib::IEncodingStreamPtr m_pEncoder;
//	istream * m_pInStream;

	void SetFileExtensionFilter(BSTR sMediaType);

public:
	// <summary>Gets the URI of the bound data</summary>
	HRESULT getURIValue(BSTR * psValue);
};

#endif